package com.ky.pro.java.dt.order.controller;


import com.ky.pro.java.dt.common.web.ResultBean;
import com.ky.pro.java.dt.order.entity.Order;
import com.ky.pro.java.dt.order.service.impl.OrderServiceImpl;
import com.sun.istack.internal.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 配餐处理表 前端控制器
 * </p>
 *
 * @author Kevin Dummy
 * @since 2021-12-26
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderServiceImpl orderService;

    @PutMapping("/{orderNo}/status/{orderStatus}")
    public ResultBean<String> updateOrderStatus(@PathVariable("orderNo") @NotNull Long orderNo,
                                                @PathVariable("orderStatus") @NotNull Integer orderStatus) {
        return orderService.updateOrderStatus(orderNo, orderStatus);
    }


    @PostMapping("/")
    public ResultBean<String> createOrder(@RequestBody Order order) {
        return orderService.save(order) ? ResultBean.genResult("创建成功") : ResultBean.genError("创建失败");
    }

    @GetMapping("/existence/orderNo/{orderNo}")
    public ResultBean<Boolean> checkExistence(@PathVariable("orderNo") Long orderNo) {
        return orderService.checkExistence(orderNo);
    }
}

